package net;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.List;

public class AcceptClient extends Thread{
	private ServerSocket server;
	private List<Socket> sockets;
	
	public AcceptClient(List<Socket> sockets) {
		this.sockets = sockets;
		try {
			server=new ServerSocket(8877);
			System.out.println("服务器启动成功！");
		} catch (IOException e) {
			System.out.println("服务器已经启动");
			System.exit(0);
		}
	}
	
	@Override
	public void run() {
		while(true){
			try {
				Socket socket=server.accept();
				sockets.add(socket);
				Receiver rc=new Receiver(socket,sockets);
				rc.start();
				System.out.println("游客"+socket.getInetAddress().getHostAddress()+"进入！");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	
	
}
